package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration//表明是配置类
@EnableSwagger2//表明是Swagger2
@ComponentScan("com.example.demo.controller")//必须存在，扫描API controller的包
public class Swagger2 {

    @Bean
    public Docket buildDocket() {//创建Docket容器
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
    }

    /*在原来2.2.0的版本中使用new ApiInfo()的方法已经过时，使用new ApiInfoBuilder()进行构造，
    需要什么参数就添加什么参数。当然也可以什么都添加。如：
    private ApiInfo apiInfo(){ return new ApiInfoBuilder().build();}*/
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("cyd大标题")
                .description("springboot swagger2")
                .termsOfServiceUrl("http://loaclhost:8080/swagger网址链接")
                //联系人信息
                .contact(new Contact("cyd", "http://blog.csdn.net/u014231523", "897287522@163.com"))
                .version("1.0.0")
                .build();
    }
}
